import Vue from "vue";

import Cookies from "js-cookie";

import Element from "element-ui";
import "./assets/styles/element-variables.scss";

import "@/assets/styles/index.scss"; // global css
import "@/assets/styles/ruoyi.scss"; // ruoyi css
import "@/common/css/font.scss"; //自定义字体注册
import App from "./App";
import store from "./store";
import router from "./router";
import directive from "./directive"; // directive
import plugins from "./plugins"; // plugins
import { download } from "@/utils/request";

import "./assets/icons"; // icon
import "./permission"; // permission control
import { getDicts } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import {
  parseTime,
  resetForm,
  addDateRange,
  selectDictLabel,
  selectDictLabels,
  handleTree,
} from "@/utils/ruoyi";
// 分页组件
import Pagination from "@/components/Pagination";
// 自定义表格工具组件
import RightToolbar from "@/components/RightToolbar";
// 富文本组件
import Editor from "@/components/Editor";
// 文件上传组件
import FileUpload from "@/components/FileUpload";
// 图片上传组件
import ImageUpload from "@/components/ImageUpload";
// 图片预览组件
import ImagePreview from "@/components/ImagePreview";
// 字典标签组件
import DictTag from "@/components/DictTag";
// 头部标签组件
import VueMeta from "vue-meta";
// 字典数据组件
import DictData from "@/components/DictData";

import Tinymce from "@/components/tinymce/index.vue";
// 打印组件
import printjs from "print-js";
import "print-js/dist/print.css";
import html2canvas from "html2canvas";
// 剪裁图片组件

import vuecut from "@/components/vuecut";
Vue.directive("preventReClick", {
  inserted(el, binding) {
    el.addEventListener("click", () => {
      if (!el.disabled) {
        el.disabled = true;
        setTimeout(() => {
          el.disabled = false;
        }, binding.value || 2000);
      }
    });
  },
});
Vue.directive("debounce-click", {
  inserted: function (el, binding) {
    let timeout;
    el.addEventListener("click", () => {
      if (!timeout) {
        timeout = setTimeout(() => {
          timeout = null;
        }, binding.value || 2000); // 默认防抖时间为 2000 毫秒，也可以通过传入参数进行设置
      }
    });
  },
});
import inputRestrictDirective from "./inputRestrictDirective.js";

Vue.directive("input-restrict", inputRestrictDirective);
//
import filters from "@/utils/filters"; // global filters

// register global utility filters
Object.keys(filters).forEach((key) => {
  Vue.filter(key, filters[key]);
});
import VScaleScreen from "v-scale-screen";

const pickerOptions = {
  shortcuts: [
    {
      text: "最近一周",
      onClick(picker) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
        picker.$emit("pick", [start, end]);
      },
    },
    {
      text: "最近一个月",
      onClick(picker) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
        picker.$emit("pick", [start, end]);
      },
    },
    {
      text: "最近三个月",
      onClick(picker) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
        picker.$emit("pick", [start, end]);
      },
    },
  ],
};
import { checkPhone } from "@/utils/validate";

function toUrl(href) {
  window.open(href, "_blank");
}
function convertSeconds(seconds) {
  const days = Math.floor(seconds / (3600 * 24));
  seconds %= (3600 * 24);
  const hours = Math.floor(seconds / 3600);
  seconds %= 3600;
  const minutes = Math.floor(seconds / 60);
  const remainingSeconds = seconds % 60;

  let result = '';

  if (days > 0) {
    result += `${days}天`;
  }
  if (hours > 0) {
    if (result.length > 0) result += '';
    result += `${hours}时`;
  }
  if (minutes > 0) {
    if (result.length > 0) result += '';
    result += `${minutes}分`;
  } else if (remainingSeconds > 0) {
    // 如果只有秒，将其转换为分钟并保留一位小数
    const minutesWithDecimal = (remainingSeconds / 60).toFixed(1);
    result += `${minutesWithDecimal}分`;
  } else if (result === '') {
    // 如果所有单位都为0，则返回 "0秒"
    result += '0分';
  }

  return result;
}
// 全局方法挂载
Vue.prototype.$convertSeconds = convertSeconds;
Vue.prototype.$toUrl = toUrl;
Vue.prototype.$checkPhone = checkPhone;
Vue.prototype.$pickerOptions = pickerOptions;
Vue.prototype.getDicts = getDicts;
Vue.prototype.getConfigKey = getConfigKey;
Vue.prototype.parseTime = parseTime;
Vue.prototype.resetForm = resetForm;
Vue.prototype.addDateRange = addDateRange;
Vue.prototype.selectDictLabel = selectDictLabel;
Vue.prototype.selectDictLabels = selectDictLabels;
Vue.prototype.download = download;
Vue.prototype.handleTree = handleTree;
Vue.prototype.$print = printjs;
Vue.prototype.$html2canvas = html2canvas;

// 全局组件挂载
import Texttooltip from "@/components/Texttooltip.vue";
Vue.component("Texttooltip", Texttooltip);
Vue.component("vuecut", vuecut);
Vue.component("DictTag", DictTag);
Vue.component("Pagination", Pagination);
Vue.component("RightToolbar", RightToolbar);
Vue.component("Editor", Editor);
Vue.component("FileUpload", FileUpload);
Vue.component("ImageUpload", ImageUpload);
Vue.component("ImagePreview", ImagePreview);
Vue.component("tinymce", Tinymce);

Vue.use(directive);
Vue.use(plugins);
Vue.use(VueMeta);
Vue.use(VScaleScreen);
DictData.install();


/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */
// 在您的 Vue 组件中
import horizontalScrollDragDirective from "./utils/horizontalScrollDragDirective.js";
// 注册自定义指令
Vue.directive("horizontal-scroll-drag", horizontalScrollDragDirective);
Vue.use(Element, {
  size: Cookies.get("size") || "medium", // set element- ui default size
});

Vue.config.productionTip = false;

new Vue({
  el: "#app",
  router,
  store,
  render: (h) => h(App),
});
